using System;
using Mbs.ComponentModel.Container.Metadata;

namespace Mbs.ComponentModel.Container.Listner
{
    [Serializable]
    public class StartableListner : KernelListnerAdapter
    {
        public StartableListner() : base(LifestyleStage.Created | LifestyleStage.Destroyed) { }

        public override void OnCreated(IComponentInfo info, object instance)
        {
            var startable = instance as IStartable;
            if (startable != null)
                startable.Start();

        }

        public override void OnDestroyed(IComponentInfo info, object instance)
        {
            var startable = instance as IStartable;
            if (startable != null)
                startable.Stop();
        }
    }
}
